<?php

/**
 * @version     $Id: view.html.php 3 2010-10-08 17:49:35Z obalyuk87@gmail.com $
 * @package     AdminSafe
 * @subpackage  Components
 * @copyright   Copyright (C) 2010 Oleksandr Balyuk (www.boolcast.com)
 * @license     http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL v2
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */
// No direct access
defined('_JEXEC') or die('Restricted access');

require_once JPATH_COMPONENT_ADMINISTRATOR . DS . 'helpers' . DS . 'AdminsafeCPanelHelper.php';
require_once JPATH_COMPONENT_ADMINISTRATOR . DS . 'classes' . DS . 'component' . DS . 'view.php';
require_once JPATH_COMPONENT_ADMINISTRATOR . DS . 'classes' . DS . 'google' . DS . 'gChart.php';

/**
 * Description of view
 *
 * @author Oleksandr Balyuk <obalyuk@boolcast.com>
 */
class AdminsafeViewAdminsafe extends AdminsafeView {

    /**
     * List of CPanel Items
     * @var array
     */
    protected $cPanelItems = array();

    /**
     * Adds stylesheets and scripts
     */
    protected function _addStylesheetsAndScripts() {
        JHTML::_('stylesheet', 'adminsafe.css', 'media/com_adminsafe/css/');

        JHTML::_('behavior.modal');
        JHTML::_('behavior.mootools');
    }

    /**
     * Loads data from database
     */
    protected function _loadData() {
        //
        if (JFactory::getUser()->gid == UserRoles::SUPER_ADMINISTRATOR) {
            $this->cPanelItems[] = $this->_getConfigurationCPanelITem();
        }

        $this->cPanelItems[] = $this->_getCPanelItem('invalidkeylog', JText::_('CAS_HACK_ATTEMPTS'), 'warning');
        $this->cPanelItems[] = $this->_getCPanelItem('accesslog', JText::_('CAS_ACCESS_LOG'), 'password');
        $this->cPanelItems[] = $this->_getCPanelItem('ipblacklist', JText::_('CAS_BANNED_IPS'), 'firewall');

        //
        $this->cPanelItems[] = $this->_getCPanelItem('license', JText::_('CAS_LICENSE'), 'license');
        $this->cPanelItems[] = $this->_getCPanelItem('credits', JText::_('CAS_CREDITS'), 'credits');
    }

    /**
     * Prepares data for display
     */
    protected function _prepareDataForDisplay() {
        
    }

    /**
     * Sets toolbar
     */
    protected function _setToolBar() {
        JToolBarHelper::title(JText::_('CAS_NAME'), 'adminsafe');
    }

    /**
     * Gets new CPanel Item
     *
     * @param string $view
     * @param string $text translated string
     * @param string $img name of the image without the extension.
     * @param string $ext
     * @return string
     */
    protected function _getCPanelItem($view, $text, $img, $ext='png') {
        //
        $url = JRoute::_("index.php?option=com_adminsafe&view=$view");
        $img = JHTML::image("media/com_adminsafe/images/48/$img.$ext", $text, $ext);
        return AdminsafeCPanelHelper::getIconHTML($url, $img, $text);
    }

    /**
     * Gets configuration Button
     *
     * @return string
     */
    protected function _getConfigurationCPanelITem() {

        $text = JText::_('CAS_CONFIGURATION');
        $url = JRoute::_('index.php?option=com_config&controller=component&component=com_adminsafe');
        $img = JHTML::image("media/com_adminsafe/images/48/config.png", $text, $ext);

        $attribs = array();
        $attribs['class'] = 'modal';
        $attribs['rel'] = "{handler: 'iframe', size: {x: 600, y: 450}}";

        return AdminsafeCPanelHelper::getIconHTML($url, $img, $text, $attribs);
    }

}